package com.study.ibmMq.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wei.zhao
 * @description:
 * @date 2022年06月22日 11:37
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class SendMessageController {

    @Value("${project.ibmmq.queue01}")
    private String queueName;

    @Autowired
    JmsTemplate jmsTemplate;

    @PostMapping("/msg/mq")
    public void sendMq(@RequestBody String msg) {
        log.info("获得报文并开始向mq发送：" + msg);
        try {
            jmsTemplate.convertAndSend(queueName, msg);
            log.info("======推送mq报文完成======");
        } catch (Exception ex) {
            log.error("发送消息失败--->{}", ex.getMessage());
        }
    }

}
